<?php 
// +----------------------------------------------------------------------
// | RXThinkCMF框架 [ RXThinkCMF ]
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 南京RXThinkCMF研发中心
// +----------------------------------------------------------------------
// | 官方网站: http://www.rxthink.cn
// +----------------------------------------------------------------------
// | Author: 牧羊人 <1175401194@qq.com>
// +----------------------------------------------------------------------

namespace app\admin\service;


use app\admin\model\OfPatentNotice;
use app\common\service\BaseService;
use think\facade\Db;

/**
 * 通知书管理-服务类
 * @author 牧羊人
 * @since: 2021/12/28
 * Class OfPatentNoticeService
 * @package app\admin\service
 */
class OfPatentNoticeService extends BaseService
{
    /**
     * 构造函数
     * LevelService constructor.
     */
    public function __construct()
    {
        $this->model = new OfPatentNotice();
    }
	
	/**
     * 获取数据列表
     * @return array
     * @since 2021/12/28
     * @author 牧羊人
     */
    public function getList()
    {
        $param = request()->param();

        // 查询条件
        $map = [];

	    // 名称
        $patent_name = isset($param['patent_name']) ? trim($param['patent_name']) : '';
        if(!empty($patent_name)){
            $url_name = Db::name("of_patent")->where("patent_name","like","%$patent_name%")->value("group_concat(inside_number) as inside_number");

            if ($url_name) {
                $map[] = ['url_name', 'in', "{$url_name}"];
            }
        }
        $company_name = isset($param['company_name']) ? trim($param['company_name']) : '';
        if ($company_name) {
            $ids = Db::name("of_company")->where('name', 'like', "%{$company_name}%")->column("id");
            $map[] = ['company_id','in',$ids];
        }
        $url_name = isset($param['url_name']) ? trim($param['url_name']) : '';
        if ($url_name) {
            $map[] = ['url_name', 'like', "%{$url_name}%"];
        }
        $patent_id = isset($param['patent_id']) ? trim($param['patent_id']) : '';
        if($patent_id){
            $map[] = ['patent_id','=',(int)$patent_id];
        }
        $type = isset($param['type']) ? trim($param['type']) : 1;
        $map[] = ['type', '=' , $type];

        $apply_number = isset($param['apply_number']) ? trim($param['apply_number']) : '';
        if($apply_number){
            $ids = Db::name("of_trademark")->where('apply_number', 'like', "%{$apply_number}%")->column("id");
            $map[] = ['patent_id','in',$ids];
        }
        
        return parent::getList($map); // TODO: Change the autogenerated stub
    }                 
}